package com.example.onlinemusic.service.impl;

import com.example.onlinemusic.mapper.UserMapper;
import com.example.onlinemusic.model.User;
import com.example.onlinemusic.service.UserService;
import com.example.onlinemusic.tools.Constant;
import com.example.onlinemusic.tools.ResponseBodyMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;

    @Override
    public User login(User loginUser) {
        User userInfo = userMapper.login(loginUser);
        if (userInfo == null) {
            return null;
        } else {
            return userInfo;
        }
    }

    @Override
    public int register(User registerUser) {
        String encode = bCryptPasswordEncoder.encode(registerUser.getPassword()); // 加密后的密码
        registerUser.setPassword(encode);

        return userMapper.register(registerUser);
    }
}
